//
//  UIAlertController+WLExtension.swift
//  HengYouCai
//
//  Created by wll on 2017/11/2.
//  Copyright © 2017年 lwj. All rights reserved.
//

import Foundation
import IQKeyboardManager


extension UIAlertController {
    /** title nil 和 ""区别：前者message文字变粗体 居中 ""正常居左 */
    @discardableResult convenience init(_ title: String?, _ message: String?, _ titleTexts: [String], _ titleTextColor: [UIColor], _ preferredStyle: UIAlertControllerStyle, _  callBack: @escaping((NSInteger,String)-> Void)) {
        
        self.init(title: title, message: message, preferredStyle: preferredStyle)
        
        for i in 0...(titleTexts.count - 1) {
            let tAction = UIAlertAction(title: titleTexts[i], style: .default, handler: { (action) in
                callBack(i,action.title!)
            })
            if i < titleTextColor.count {
                tAction.setValue(titleTextColor[i], forKeyPath: "titleTextColor")
            }
            self.addAction(tAction)
        }
//        JCWShareApplication.delegate?.window?.currentViewController?.present(self, animated: true, completion: nil)
        MainTabBarViewController.obtainTopViewController()?.present(self, animated: true, completion: nil)
    }
}
